import 'package:favor_cate/core/model/category_model.dart';
import 'package:favor_cate/core/services/json_parse.dart';
import 'package:favor_cate/ui/pages/home/home_category_item.dart';
import 'package:flutter/cupertino.dart';
import 'package:favor_cate/core/extension/double_extension.dart';
import 'package:favor_cate/core/extension/int_extension.dart';
import 'package:flutter/material.dart';

class HomeContent extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<List<CategoryModel>>(
        future: JsonParse.getCategoryDate(),

        builder: (ctx, snapshot) {
          if(!snapshot.hasData) return Center(child: CircularProgressIndicator());
          if(snapshot.error != null) return Center(child: Text("请求失败"),);
          final List<CategoryModel>? categories = snapshot.data;
          return GridView.builder(
              padding: EdgeInsets.all(40.px),
              itemCount: categories!.length,
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  childAspectRatio: 14/9,
                  crossAxisCount: 2,
                  mainAxisSpacing: 20.px,
                  crossAxisSpacing: 20.px
              ),
              itemBuilder: (ctx, index) {
                return HomeCategoryItem(categories[index]);
              });

    });
  }
}


